function loopLength(n) {
    while (n % 2 === 0) n /= 2;
    while (n % 5 === 0) n /= 5;

    let a = 9, tot = 1;
    while (a % n !== 0) {
        a = (a * 10 + 9) % n;
        ++tot;
    }
    return tot;
}

function reciprocalCycles(n) {
    let best = 1;
    for (let i = 1; i <= n; i++) {
        if (best < loopLength(i)) best = i;
    }
    return best;
}

console.log(reciprocalCycles(1000));